package Publisher

import (

	"container/list"
)
type Handler interface {//这里主要参考了Go里HTTP包的实现
	Serve(int)
}

type HandlerFunc func(args int)
func (f HandlerFunc) Serve(args int) {
	f(args)
}

type Publish struct {
	Sublist *list.List
	Value        int
}
func NewPublisher() *Publish {
	p := new(Publish)
	p.Sublist = list.New()
	p.Value = 22
	return p
}
func (p *Publish) AddSubscriber(f HandlerFunc) {//可以添加任何方法，只要是HandlerFunc的
	p.Sublist.PushBack(f)
}
func (p *Publish) Notify(args int) {
	for f := p.Sublist.Front(); f != nil; f = f.Next() {
		f.Value.(Handler).Serve(args)
	}
}